package com.yuntsg.ruiijn.databse_search.service;

import common.util.NacosUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Slf4j
@Component
@SuppressWarnings("all")
public class FeatureService {

    @Autowired
    private NacosUtil nacosUtil;


    private Map<String, Integer> featureMap = new HashMap<>();

    public List<Float> imageFeature(String path) {

        List<Float> reslut = new ArrayList<>();
        int retryCount = 0;
        while (retryCount < 3) {
            try {
                reslut = nacosUtil.imageFeature(path);
                break;
            } catch (Exception e) {
                retryCount++;
                if (retryCount >= 3) {
                    throw new RuntimeException("Failed after retries", e);
                }
            }
        }
        return reslut;
    }


    public Integer imageClassify(String path) {

        try {
            return nacosUtil.imageClassify(path);
        } catch (Exception e) {
            log.error("提取初级分类失败");
            return 4;
        }
    }

    public Integer imageClassifyStep(String path) {

        try {
            return nacosUtil.imageClassifyStep(path);
        } catch (Exception e) {
            log.error("提取次级分类失败");
            return 0;
        }

    }
}